Skip to content

fix SQLITE CANTOPEN errorno:14 issue#1

Open
acdmft wants to merge 1 commit intoMaximStone:mainfrom
acdmft:fix/sqlite_cantopen_erron14
Open

fix SQLITE CANTOPEN errorno:14 issue#1
acdmft wants to merge 1 commit intoMaximStone:mainfrom
acdmft:fix/sqlite_cantopen_erron14

Conversation

@acdmft
Copy link

@acdmft acdmft commented Dec 21, 2025

When running 'npm run dev' or 'docker compose up --build' command I received 'SQLITE CANTOPEN errorno:14' error. This was caused because DataSource class in dataSource.ts couldn't find the database file.
Proposed fix: add DB_PATH environment variable that is resolved to the absolute path of the project (should be set in .env file). Also added in 'environment' section in docker-compose.yml so that when app is launched using 'docker compose up --build' command, docker get the path from DB_PATH variable in 'docker-compose.yml'.
Node image was changed in Dockerfile from node:20-alpine to node:20-slim because node:20-alpine bugged.
Tested on Linux Ubuntu.

@acdmft acdmft changed the title fix: add DB_PATH environment variable to fix the error with sqlite er… fix SQLITE CANTOPEN errorno:14 issue Dec 22, 2025
@MaximStone MaximStone requested a review from Copilot December 23, 2025 09:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a SQLite database connection error (CANTOPEN errno:14) by introducing a configurable database path via the DB_PATH environment variable and adjusting the Docker configuration.

Key changes:

  • Added DB_PATH environment variable support in the TypeORM DataSource configuration with fallback to "data.db"
  • Modified docker-compose.yml to set DB_PATH and changed volume mapping from file-based to directory-based
  • Updated README documentation with DB_PATH configuration instructions

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
src/dataSource.ts Added DB_PATH environment variable support with fallback for database path configuration
docker-compose.yml Added DB_PATH environment variable and changed volume mapping from ./data.db to ./data directory
README.md Documented the new DB_PATH environment variable in the setup instructions
Dockerfile Changed base image from node:20-alpine to node:20-slim

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

environment:
- TELEGRAM_TOKEN=${TELEGRAM_TOKEN}
- WEBAPP_URL=${WEBAPP_URL}
- DB_PATH=/app/data.db
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a trailing space after the DB_PATH value. Remove the space at the end of this line to avoid potential issues with the environment variable value.

Suggested change
- DB_PATH=/app/data.db
- DB_PATH=/app/data.db

Copilot uses AI. Check for mistakes.
export const AppDataSource = new DataSource({
type: "sqlite",
database: "data.db",
database: process.env.DB_PATH || "data.db",
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's extra spacing between 'database:' and 'process.env.DB_PATH'. While this doesn't affect functionality, it's inconsistent with the typical code style. Consider using a single space for consistency.

Suggested change
database: process.env.DB_PATH || "data.db",
database: process.env.DB_PATH || "data.db",

Copilot uses AI. Check for mistakes.
```env
TELEGRAM_TOKEN=your_telegram_bot_token
WEBAPP_URL=http://localhost:5000
DB_PATH=/path/to/data/data.db # use in development mode (not needed for docker-compose setup)
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation suggests using an absolute path like "/path/to/data/data.db" but this might be confusing. For local development, the path should typically be relative to the project root (e.g., "./data/data.db" or an absolute path using __dirname). Consider clarifying the expected path format or providing a concrete example that users can actually use.

Suggested change
DB_PATH=/path/to/data/data.db # use in development mode (not needed for docker-compose setup)
DB_PATH=./data/data.db # путь к файлу БД относительно корня проекта (для локальной разработки; не нужен для docker-compose)

Copilot uses AI. Check for mistakes.
@@ -1,4 +1,4 @@
FROM node:20-alpine
FROM node:20-slim
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Dockerfile doesn't create the /app/data directory that's needed for the database file when using DB_PATH=/app/data.db. Consider adding 'RUN mkdir -p /app/data' before the CMD instruction to ensure the directory exists when the container starts.

Copilot uses AI. Check for mistakes.
environment:
- TELEGRAM_TOKEN=${TELEGRAM_TOKEN}
- WEBAPP_URL=${WEBAPP_URL}
- DB_PATH=/app/data.db
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a mismatch between the DB_PATH environment variable and the volume mapping. DB_PATH is set to /app/data.db but the volume maps ./data to /data (not /app/data). This will cause the database file to be created at /app/data.db inside the container, which won't be persisted to the host because the volume is mounted at /data. Either change DB_PATH to /data/data.db or change the volume mapping to ./data:/app/data.

Suggested change
- DB_PATH=/app/data.db
- DB_PATH=/data/data.db

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants